.class public Lcom/openfeint/internal/ImagePicker;
.super Ljava/lang/Object;
.source "ImagePicker.java"


# static fields
.field public static final IMAGE_PICKER_REQ_ID:I = 0x2719

.field protected static final TAG:Ljava/lang/String; = "ImagePicker"


# direct methods
.method public constructor <init>()V
    .locals 0

    .prologue
    .line 24
    invoke-direct {p0}, Ljava/lang/Object;-><init>()V

    return-void
.end method

.method public static compressAndUpload(Landroid/graphics/Bitmap;Ljava/lang/String;Lcom/openfeint/internal/OpenFeintInternal$IUploadDelegate;)V
    .locals 3
    .parameter "image"
    .parameter "apiPath"
    .parameter "delegate"

    .prologue
    .line 72
    new-instance v0, Ljava/io/ByteArrayOutputStream;

    invoke-direct {v0}, Ljava/io/ByteArrayOutputStream;-><init>()V

    .line 73
    .local v0, out:Ljava/io/ByteArrayOutputStream;
    sget-object v1, Landroid/graphics/Bitmap$CompressFormat;->PNG:Landroid/graphics/Bitmap$CompressFormat;

    const/16 v2, 0x64

    invoke-virtual {p0, v1, v2, v0}, Landroid/graphics/Bitmap;->compress(Landroid/graphics/Bitmap$CompressFormat;ILjava/io/OutputStream;)Z

    .line 74
    invoke-static {p1, v0, p2}, Lcom/openfeint/internal/ImagePicker;->upload(Ljava/lang/String;Ljava/io/ByteArrayOutputStream;Lcom/openfeint/internal/OpenFeintInternal$IUploadDelegate;)V

    .line 75
    return-void
.end method

.method public static isImagePickerActivityResult(I)Z
    .locals 1
    .parameter "requestCode"

    .prologue
    .line 41
    const/16 v0, 0x2719

    if-ne p0, v0, :cond_0

    const/4 v0, 0x1

    :goto_0
    return v0

    :cond_0
    const/4 v0, 0x0

    goto :goto_0
.end method

.method public static onImagePickerActivityResult(Landroid/app/Activity;IILandroid/content/Intent;)Landroid/graphics/Bitmap;
    .locals 6
    .parameter "currentActivity"
    .parameter "resultCode"
    .parameter "maxLength"
    .parameter "returnedIntent"

    .prologue
    .line 45
    const/4 v0, -0x1

    if-ne p1, v0, :cond_1

    .line 46
    invoke-virtual {p3}, Landroid/content/Intent;->getData()Landroid/net/Uri;

    move-result-object v1

    .line 47
    .local v1, selectedImage:Landroid/net/Uri;
    const/4 p1, 0x2

    new-array v2, p1, [Ljava/lang/String;

    .end local p1
    const/4 p1, 0x0

    const-string p3, "_data"

    .end local p3
    aput-object p3, v2, p1

    const/4 p1, 0x1

    const-string p3, "orientation"

    aput-object p3, v2, p1

    .line 49
    .local v2, columns:[Ljava/lang/String;
    invoke-virtual {p0}, Landroid/app/Activity;->getContentResolver()Landroid/content/ContentResolver;

    move-result-object v0

    const/4 v3, 0x0

    const/4 v4, 0x0

    const/4 v5, 0x0

    invoke-virtual/range {v0 .. v5}, Landroid/content/ContentResolver;->query(Landroid/net/Uri;[Ljava/lang/String;Ljava/lang/String;[Ljava/lang/String;Ljava/lang/String;)Landroid/database/Cursor;

    move-result-object p1

    .line 50
    .local p1, cursor:Landroid/database/Cursor;
    if-eqz p1, :cond_0

    .line 51
    invoke-interface {p1}, Landroid/database/Cursor;->moveToFirst()Z

    .line 53
    const/4 p0, 0x0

    aget-object p0, v2, p0

    .end local p0
    invoke-interface {p1, p0}, Landroid/database/Cursor;->getColumnIndex(Ljava/lang/String;)I

    move-result p0

    .line 54
    .local p0, columnIndex:I
    invoke-interface {p1, p0}, Landroid/database/Cursor;->getString(I)Ljava/lang/String;

    move-result-object p0

    .line 55
    .local p0, filePath:Ljava/lang/String;
    const/4 p3, 0x1

    aget-object p3, v2, p3

    invoke-interface {p1, p3}, Landroid/database/Cursor;->getColumnIndex(Ljava/lang/String;)I

    move-result p3

    invoke-interface {p1, p3}, Landroid/database/Cursor;->getInt(I)I

    move-result p3

    .line 56
    .local p3, rotation:I
    invoke-interface {p1}, Landroid/database/Cursor;->close()V

    .line 58
    invoke-static {p0, p2, p3}, Lcom/openfeint/internal/ImagePicker;->resize(Ljava/lang/String;II)Landroid/graphics/Bitmap;

    move-result-object p0

    .line 59
    .local p0, image:Landroid/graphics/Bitmap;
    const-string p1, "ImagePicker"

    .end local p1           #cursor:Landroid/database/Cursor;
    new-instance p2, Ljava/lang/StringBuilder;

    .end local p2
    const-string p3, "image! "

    .end local p3           #rotation:I
    invoke-direct {p2, p3}, Ljava/lang/StringBuilder;-><init>(Ljava/lang/String;)V

    invoke-virtual {p0}, Landroid/graphics/Bitmap;->getWidth()I

    move-result p3

    invoke-virtual {p2, p3}, Ljava/lang/StringBuilder;->append(I)Ljava/lang/StringBuilder;

    move-result-object p2

    const-string p3, "x"

    invoke-virtual {p2, p3}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object p2

    invoke-virtual {p0}, Landroid/graphics/Bitmap;->getHeight()I

    move-result p3

    invoke-virtual {p2, p3}, Ljava/lang/StringBuilder;->append(I)Ljava/lang/StringBuilder;

    move-result-object p2

    invoke-virtual {p2}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;

    move-result-object p2

    invoke-static {p1, p2}, Lcom/openfeint/internal/OpenFeintInternal;->log(Ljava/lang/String;Ljava/lang/String;)V

    .line 68
    .end local v1           #selectedImage:Landroid/net/Uri;
    .end local v2           #columns:[Ljava/lang/String;
    .end local p0           #image:Landroid/graphics/Bitmap;
    :goto_0
    return-object p0

    .line 63
    .restart local v1       #selectedImage:Landroid/net/Uri;
    .restart local v2       #columns:[Ljava/lang/String;
    .local p0, currentActivity:Landroid/app/Activity;
    .restart local p1       #cursor:Landroid/database/Cursor;
    .restart local p2
    :cond_0
    const p0, 0x7f04000c

    invoke-static {p0}, Lcom/openfeint/internal/OpenFeintInternal;->getRString(I)Ljava/lang/String;

    .end local p0           #currentActivity:Landroid/app/Activity;
    move-result-object p0

    .line 64
    .local p0, msg:Ljava/lang/String;
    invoke-static {}, Lcom/openfeint/internal/OpenFeintInternal;->getInstance()Lcom/openfeint/internal/OpenFeintInternal;

    move-result-object p1

    .end local p1           #cursor:Landroid/database/Cursor;
    invoke-virtual {p1}, Lcom/openfeint/internal/OpenFeintInternal;->getContext()Landroid/content/Context;

    move-result-object p1

    const/4 p2, 0x1

    invoke-static {p1, p0, p2}, Landroid/widget/Toast;->makeText(Landroid/content/Context;Ljava/lang/CharSequence;I)Landroid/widget/Toast;

    .end local p2
    move-result-object p0

    .end local p0           #msg:Ljava/lang/String;
    invoke-virtual {p0}, Landroid/widget/Toast;->show()V

    .line 68
    .end local v1           #selectedImage:Landroid/net/Uri;
    .end local v2           #columns:[Ljava/lang/String;
    :cond_1
    const/4 p0, 0x0

    goto :goto_0
.end method

.method private static preScaleImage(Ljava/lang/String;I)Landroid/graphics/Bitmap;
    .locals 9
    .parameter "filePath"
    .parameter "maxLength"

    .prologue
    const/4 v8, 0x0

    .line 100
    new-instance v1, Ljava/io/File;

    invoke-direct {v1, p0}, Ljava/io/File;-><init>(Ljava/lang/String;)V

    .line 104
    .local v1, f:Ljava/io/File;
    :try_start_0
    new-instance v3, Landroid/graphics/BitmapFactory$Options;

    invoke-direct {v3}, Landroid/graphics/BitmapFactory$Options;-><init>()V

    .line 105
    .local v3, o:Landroid/graphics/BitmapFactory$Options;
    const/4 v6, 0x1

    iput-boolean v6, v3, Landroid/graphics/BitmapFactory$Options;->inJustDecodeBounds:Z

    .line 106
    new-instance v6, Ljava/io/FileInputStream;

    invoke-direct {v6, v1}, Ljava/io/FileInputStream;-><init>(Ljava/io/File;)V

    const/4 v7, 0x0

    invoke-static {v6, v7, v3}, Landroid/graphics/BitmapFactory;->decodeStream(Ljava/io/InputStream;Landroid/graphics/Rect;Landroid/graphics/BitmapFactory$Options;)Landroid/graphics/Bitmap;

    .line 109
    iget v6, v3, Landroid/graphics/BitmapFactory$Options;->outWidth:I

    iget v7, v3, Landroid/graphics/BitmapFactory$Options;->outHeight:I

    invoke-static {v6, v7}, Ljava/lang/Math;->min(II)I

    move-result v2

    .line 110
    .local v2, minDim:I
    const/4 v5, 0x1

    .line 111
    .local v5, scale:I
    :goto_0
    div-int/lit8 v6, v2, 0x2

    if-gt v6, p1, :cond_0

    .line 117
    new-instance v4, Landroid/graphics/BitmapFactory$Options;

    invoke-direct {v4}, Landroid/graphics/BitmapFactory$Options;-><init>()V

    .line 118
    .local v4, o2:Landroid/graphics/BitmapFactory$Options;
    iput v5, v4, Landroid/graphics/BitmapFactory$Options;->inSampleSize:I

    .line 119
    new-instance v6, Ljava/io/FileInputStream;

    invoke-direct {v6, v1}, Ljava/io/FileInputStream;-><init>(Ljava/io/File;)V

    const/4 v7, 0x0

    invoke-static {v6, v7, v4}, Landroid/graphics/BitmapFactory;->decodeStream(Ljava/io/InputStream;Landroid/graphics/Rect;Landroid/graphics/BitmapFactory$Options;)Landroid/graphics/Bitmap;

    move-result-object v6

    .line 124
    .end local v2           #minDim:I
    .end local v3           #o:Landroid/graphics/BitmapFactory$Options;
    .end local v4           #o2:Landroid/graphics/BitmapFactory$Options;
    .end local v5           #scale:I
    :goto_1
    return-object v6

    .line 112
    .restart local v2       #minDim:I
    .restart local v3       #o:Landroid/graphics/BitmapFactory$Options;
    .restart local v5       #scale:I
    :cond_0
    div-int/lit8 v2, v2, 0x2
    :try_end_0
    .catch Ljava/io/FileNotFoundException; {:try_start_0 .. :try_end_0} :catch_0

    .line 113
    add-int/lit8 v5, v5, 0x1

    goto :goto_0

    .line 121
    .end local v2           #minDim:I
    .end local v3           #o:Landroid/graphics/BitmapFactory$Options;
    .end local v5           #scale:I
    :catch_0
    move-exception v6

    move-object v0, v6

    .line 122
    .local v0, e:Ljava/io/FileNotFoundException;
    const-string v6, "ImagePicker"

    invoke-virtual {v0}, Ljava/io/FileNotFoundException;->toString()Ljava/lang/String;

    move-result-object v7

    invoke-static {v6, v7}, Lcom/openfeint/internal/OpenFeintInternal;->log(Ljava/lang/String;Ljava/lang/String;)V

    move-object v6, v8

    .line 124
    goto :goto_1
.end method

.method private static resize(Ljava/lang/String;II)Landroid/graphics/Bitmap;
    .locals 12
    .parameter "filePath"
    .parameter "maxLength"
    .parameter "rotation"

    .prologue
    const/4 v6, 0x0

    .line 78
    invoke-static {p0, p1}, Lcom/openfeint/internal/ImagePicker;->preScaleImage(Ljava/lang/String;I)Landroid/graphics/Bitmap;

    move-result-object v0

    .line 80
    .local v0, image:Landroid/graphics/Bitmap;
    invoke-virtual {v0}, Landroid/graphics/Bitmap;->getWidth()I

    move-result v10

    .line 81
    .local v10, width:I
    invoke-virtual {v0}, Landroid/graphics/Bitmap;->getHeight()I

    move-result v7

    .line 82
    .local v7, height:I
    if-le v7, v10, :cond_0

    const/4 v4, 0x1

    move v9, v4

    .line 85
    .local v9, tall:Z
    :goto_0
    if-eqz v9, :cond_1

    move v1, v6

    .line 86
    .local v1, _x:I
    :goto_1
    if-eqz v9, :cond_2

    sub-int v4, v7, v10

    div-int/lit8 v4, v4, 0x2

    move v2, v4

    .line 87
    .local v2, _y:I
    :goto_2
    if-eqz v9, :cond_3

    move v3, v10

    .line 89
    .local v3, _length:I
    :goto_3
    int-to-float v4, p1

    int-to-float v11, v3

    div-float v8, v4, v11

    .line 91
    .local v8, scale:F
    new-instance v5, Landroid/graphics/Matrix;

    invoke-direct {v5}, Landroid/graphics/Matrix;-><init>()V

    .line 92
    .local v5, transform:Landroid/graphics/Matrix;
    invoke-virtual {v5, v8, v8}, Landroid/graphics/Matrix;->postScale(FF)Z

    .line 93
    int-to-float v4, p2

    invoke-virtual {v5, v4}, Landroid/graphics/Matrix;->postRotate(F)Z

    move v4, v3

    .line 95
    invoke-static/range {v0 .. v6}, Landroid/graphics/Bitmap;->createBitmap(Landroid/graphics/Bitmap;IIIILandroid/graphics/Matrix;Z)Landroid/graphics/Bitmap;

    move-result-object v4

    return-object v4

    .end local v1           #_x:I
    .end local v2           #_y:I
    .end local v3           #_length:I
    .end local v5           #transform:Landroid/graphics/Matrix;
    .end local v8           #scale:F
    .end local v9           #tall:Z
    :cond_0
    move v9, v6

    .line 82
    goto :goto_0

    .line 85
    .restart local v9       #tall:Z
    :cond_1
    sub-int v4, v10, v7

    div-int/lit8 v4, v4, 0x2

    move v1, v4

    goto :goto_1

    .restart local v1       #_x:I
    :cond_2
    move v2, v6

    .line 86
    goto :goto_2

    .restart local v2       #_y:I
    :cond_3
    move v3, v7

    .line 87
    goto :goto_3
.end method

.method public static show(Landroid/app/Activity;)V
    .locals 5
    .parameter "currentActivity"

    .prologue
    .line 29
    const-string v3, "activity"

    invoke-virtual {p0, v3}, Landroid/app/Activity;->getSystemService(Ljava/lang/String;)Ljava/lang/Object;

    move-result-object v0

    check-cast v0, Landroid/app/ActivityManager;

    .line 30
    .local v0, am:Landroid/app/ActivityManager;
    new-instance v2, Landroid/app/ActivityManager$MemoryInfo;

    invoke-direct {v2}, Landroid/app/ActivityManager$MemoryInfo;-><init>()V

    .line 31
    .local v2, mi:Landroid/app/ActivityManager$MemoryInfo;
    invoke-virtual {v0, v2}, Landroid/app/ActivityManager;->getMemoryInfo(Landroid/app/ActivityManager$MemoryInfo;)V

    .line 33
    new-instance v1, Landroid/content/Intent;

    const-string v3, "android.intent.action.PICK"

    sget-object v4, Landroid/provider/MediaStore$Images$Media;->INTERNAL_CONTENT_URI:Landroid/net/Uri;

    invoke-direct {v1, v3, v4}, Landroid/content/Intent;-><init>(Ljava/lang/String;Landroid/net/Uri;)V

    .line 34
    .local v1, intent:Landroid/content/Intent;
    const-string v3, "image/*"

    invoke-virtual {v1, v3}, Landroid/content/Intent;->setType(Ljava/lang/String;)Landroid/content/Intent;

    .line 35
    const/16 v3, 0x2719

    invoke-virtual {p0, v1, v3}, Landroid/app/Activity;->startActivityForResult(Landroid/content/Intent;I)V

    .line 36
    return-void
.end method

.method private static upload(Ljava/lang/String;Ljava/io/ByteArrayOutputStream;Lcom/openfeint/internal/OpenFeintInternal$IUploadDelegate;)V
    .locals 6
    .parameter "apiPath"
    .parameter "stream"
    .parameter "delegate"

    .prologue
    .line 128
    invoke-static {}, Lcom/openfeint/internal/OpenFeintInternal;->getInstance()Lcom/openfeint/internal/OpenFeintInternal;

    move-result-object v0

    const-string v2, "profile.png"

    invoke-virtual {p1}, Ljava/io/ByteArrayOutputStream;->toByteArray()[B

    move-result-object v3

    const-string v4, "image/png"

    move-object v1, p0

    move-object v5, p2

    invoke-virtual/range {v0 .. v5}, Lcom/openfeint/internal/OpenFeintInternal;->uploadFile(Ljava/lang/String;Ljava/lang/String;[BLjava/lang/String;Lcom/openfeint/internal/OpenFeintInternal$IUploadDelegate;)V

    .line 129
    return-void
.end method
